package cn.itcast.order.service;


import cn.itcast.order.mapper.OrderMapper;
import cn.itcast.order.pojo.Order;

import com.example.clients.UserClient;
import com.example.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrderService {

    @Autowired
    private OrderMapper orderMapper;
//    @Autowired
//    private RestTemplate restTemplate;
    @Autowired
    private UserClient userClient;

    public Order queryOrderById(Long orderId) {
        // 1.查询订单
        Order order = orderMapper.findById(orderId);
//        Long id=order.getUserId();
//        String url="http://userservice/user/"+id;
//        User u=restTemplate.getForObject(url,User.class);
        User u=userClient.queryById(order.getUserId());
        order.setUser(u);
        // 4.返回
        return order;
    }

}
